home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / Plug-in - DistanceProxyGroup / src / dpgIO.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  5.7 KB  |  229 lines  |  [TEXT/MPS ]

  1. /******************************************************************************
  2.  **                                                                             **
  3.  **     Module:        dpgIO.c                                                      **
  4.  **                                                                          **
  5.  **                                                                          **
  6.  **                                                                          **
  7.  **                                                                          **
  8.  **                                                                          **
  9.  **     Copyright (C) 1995-1996 Apple Computer, Inc.  All rights reserved.     **
  10.  **                                                                          **
  11.  **                                                                          **
  12.  *****************************************************************************/
  13.  
  14. #include "dpg.h"
  15. #include "dpgIO.h"
  16. #include "dpgMemory.h"
  17.  
  18. /*===========================================================================*\
  19.  *
  20.  *    Routine:    exDistanceProxyDistanceList_Read()
  21.  *
  22.  *    Comments:    
  23.  *
  24. \*===========================================================================*/
  25. static TQ3Status exDistanceProxyDistanceList_Read(
  26.     TQ3GroupObject        group,
  27.     TQ3FileObject        file)
  28. {
  29.     unsigned long    flag;
  30.     float            distance;
  31.     unsigned long    i, cnt;
  32.  
  33.     TQ3DistanceProxyDisplayGroupPrivate    *gPriv;
  34.     
  35.     gPriv = DPG_GETPRIVATE(group);
  36.     
  37.     if (Q3Uns32_Read(&cnt, file) == kQ3Failure)
  38.         return kQ3Failure;
  39.     
  40.     for (i=0, gPriv->distIOTblCnt = 0; i < cnt; i++) 
  41.     {
  42.         if (Q3Uns32_Read(&flag, file) == kQ3Failure)
  43.             return kQ3Failure;
  44.         
  45.         if (Q3Float32_Read(&distance, file) == kQ3Failure)
  46.             return kQ3Failure;
  47.             
  48.         if (flag == kQ3True) {
  49.             gPriv->distIOTbl = dpgRealloc(
  50.                                     gPriv->distIOTbl, 
  51.                                     sizeof(TQ3DistanceIOData) * (gPriv->distIOTblCnt+1));
  52.             if (!gPriv->distIOTbl)
  53.             {
  54.                 gPriv->distIOTblCnt = 0;
  55.                 dpgFree(gPriv->distIOTbl);
  56.                 gPriv->distIOTbl = 0;
  57.                 return kQ3Failure;
  58.             }                
  59.             gPriv->distIOTbl[gPriv->distIOTblCnt].distance = distance;
  60.             gPriv->distIOTbl[gPriv->distIOTblCnt].index    = i;
  61.     
  62.             gPriv->distIOTblCnt++;
  63.         }
  64.     }
  65.     return kQ3Success;
  66. }
  67.  
  68. /*===========================================================================*\
  69.  *
  70.  *    Routine:    exDistanceProxyDistanceList_Traverse()
  71.  *
  72.  *    Comments:    
  73.  *
  74. \*===========================================================================*/
  75. static unsigned long exDistanceProxyDistanceList_Traverse(
  76.     TQ3GroupObject        group)
  77. {
  78.     TQ3DistanceProxyDisplayGroupPrivate    *gPriv;
  79.     unsigned long size = 0;
  80.     
  81.     gPriv = DPG_GETPRIVATE(group);
  82.     
  83.     Q3Group_CountObjects(group, &size);
  84.  
  85.     size =     4 /* unsigned long */ + 
  86.                (size *  (4 /* boolean */ + 4 /* float */));
  87.                
  88.     return size;
  89. }
  90.  
  91. /*===========================================================================*\
  92.  *
  93.  *    Routine:    exDistanceProxyDistanceList_Write()
  94.  *
  95.  *    Comments:    
  96.  *
  97. \*===========================================================================*/
  98. static TQ3Status exDistanceProxyDistanceList_Write(
  99.     TQ3GroupObject            group,
  100.     TQ3FileObject            file)
  101. {
  102.     TQ3DistanceProxyDisplayGroupPrivate    *gPriv;
  103.     TQ3GroupPosition                    position;
  104.     unsigned long                        cnt;
  105.     
  106.     gPriv = DPG_GETPRIVATE(group);
  107.     
  108.     if (Q3Comment_Write("Distance Pair", file) == kQ3Failure)
  109.         return kQ3Failure;
  110.  
  111.     Q3Group_CountObjects(group, &cnt);
  112.  
  113.     if ((Q3Uns32_Write(cnt, file) == kQ3Failure) ||
  114.         (Q3Comment_Write("Count", file) == kQ3Failure))
  115.         return kQ3Failure;
  116.  
  117.     for (Q3Group_GetFirstPosition(group, &position); position != NULL;)
  118.     {
  119.         float distance;
  120.         unsigned long flag;
  121.  
  122.         flag = (unsigned long)exDistanceProxyGroup_GetDistanceAtPosition(group, position, &distance);
  123.         
  124.         if ((Q3Uns32_Write(flag, file) == kQ3Failure) ||
  125.             (Q3Float32_Write(distance, file) == kQ3Failure) ||
  126.             (Q3NewLine_Write(file) == kQ3Failure))
  127.             return kQ3Failure;
  128.  
  129.         Q3Group_GetNextPosition(group, &position);
  130.     } 
  131.     
  132.     return kQ3Success;
  133. }
  134.     
  135. /*===========================================================================*\
  136.  *
  137.  *    Routine:    exDistanceProxyGroup_Read()
  138.  *
  139.  *    Comments:    
  140.  *
  141. \*===========================================================================*/
  142. TQ3GroupObject exDistanceProxyGroup_Read(
  143.     TQ3FileObject        file)
  144. {
  145.     TQ3Point3D         refPt;
  146.     unsigned long    flags;
  147.     TQ3GroupObject    group;
  148.     
  149.     /* XXX EiFileReadState_BeginGroup(file); */
  150.     
  151.     if ((Q3Point3D_Read(&refPt, file) == kQ3Failure) ||
  152.         (Q3Uns32_Read(&flags, file) == kQ3Failure))
  153.         return NULL;
  154.         
  155.     group = exDistanceProxyGroup_New(&refPt, flags);
  156.     
  157.     if (group == NULL)
  158.         return NULL;
  159.         
  160.     if (exDistanceProxyDistanceList_Read(group, file) == kQ3Failure)
  161.     {
  162.         Q3Object_Dispose(group);
  163.         group = NULL;
  164.     }
  165.  
  166.     return group;
  167. }
  168.  
  169. /*===========================================================================*\
  170.  *
  171.  *    Routine:    exDistanceProxyGroup_Traverse()
  172.  *
  173.  *    Comments:    
  174.  *
  175. \*===========================================================================*/
  176. TQ3Status exDistanceProxyGroup_Traverse(
  177.     TQ3GroupObject        group,
  178.     void                *unused,
  179.     TQ3ViewObject        view)
  180. {
  181.     unsigned long size;
  182.     
  183.     unused;    /* Unused */
  184.     
  185.     /*
  186.     TQ3Point3D         refPt   = (float * 3) = 12
  187.     unsigned long     flags     = 4
  188.     
  189.     total size = 16
  190.     */
  191.     
  192.     size = 16 + exDistanceProxyDistanceList_Traverse(group);
  193.     
  194.     if (Q3XView_SubmitWriteData(view, size, group, NULL) == kQ3Failure)
  195.         return kQ3Failure;
  196.         
  197.     //if (EiView_TraverseObjectClass(view, EgDisplayGroupStateClass, group) == kQ3Failure)
  198.     //    return kQ3Failure;
  199.     
  200.     return kQ3Success;
  201. }
  202.  
  203. /*===========================================================================*\
  204.  *
  205.  *    Routine:    exDistanceProxyGroup_Write()
  206.  *
  207.  *    Comments:    
  208.  *
  209. \*===========================================================================*/
  210.  
  211. TQ3Status exDistanceProxyGroup_Write(
  212.     TQ3GroupObject        group,
  213.     TQ3FileObject        file)
  214. {
  215.     TQ3DistanceProxyDisplayGroupPrivate    *gPriv;
  216.     unsigned long size = 0;
  217.     
  218.     gPriv = DPG_GETPRIVATE(group);
  219.     
  220.     if ((Q3NewLine_Write(file) == kQ3Failure) ||
  221.         (Q3Point3D_Write(&gPriv->refPt, file) == kQ3Failure) ||
  222.         (Q3Comment_Write("reference point", file) == kQ3Failure) ||
  223.         (Q3Uns32_Write(gPriv->flag, file) == kQ3Failure) ||
  224.         (Q3Comment_Write("flag", file) == kQ3Failure) ||
  225.         (exDistanceProxyDistanceList_Write(group, file) == kQ3Failure))
  226.             return kQ3Failure;
  227.     
  228.     return kQ3Success;
  229. }